package com.atguigu.vod.controller;

import com.atguigu.commonutils.R;
import com.atguigu.vod.service.VopUpload;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * @author cyt
 * @create 2020-05-10 16:51
 */

@RestController
@RequestMapping("/eduvod/video")
public class VodController {

    @Autowired
    VopUpload vopUpload;

    // 上传视频
    @PostMapping("/uploadVideo")
    public R uploadVideo(MultipartFile file) throws IOException {
        String videoId = vopUpload.uploadVideo(file);
        System.out.println("videoId" + videoId);
        return R.ok().data("videoId", videoId);
    }
    // 删除视频

    @DeleteMapping("/deleteYunVideo/{id}")
    public R deleteVideo(@PathVariable("id") String id) {
        vopUpload.deleteVideo(id);
        return R.ok().message("删除视频成功");
    }

    /**
     * 批量删除视频
     *
     * @param videoIdList
     * @return
     */
    @DeleteMapping("delete-batch")
    public R removeVideoList(
            @ApiParam(name = "videoIdList", value = "云端视频id", required = true)
            @RequestParam("videoIdList") List videoIdList) {
        vopUpload.removeVideoList(videoIdList);
        return R.ok().message("视频删除成功");
    }
}
